class LiberadosController < ApplicationController
  before_filter :back, :only => [:index]

  active_scaffold :transporte do |config|
    config.label = "Transportes Liberados"

    config.columns.add :ndt_novo, :data_inicio, :etq, :m_novo, :pares_novo, :cxs_novo, :peso_novo, :armazenados_em

    config.list.columns = [:armazenados_em, :ndt, :pares, :cxs, :m, :peso, :destino, :tipo, :transportadora, :status, :data_inicio, :ended_at]
    config.update.columns = [:status,  :obs_trans, :etiqueta ]
    config.show.columns = [:data_inicio, :ndt, :pares_novo, :m_novo,
      :updated_at, :depositos, :destino, :status, :tipo,
      :transportadora, :user, :etq, :obs_trans]

    config.theme = :blue

    config.columns[:data_inicio].label = "DATA"
    config.columns[:cxs_novo].label = "CXS"
    config.columns[:cxs].label = "CXS"
    config.columns[:etiqueta].label = "ETQ"
    config.columns[:etq].label = "ETQ"
    config.columns[:m_novo].label = "VOLUME"
    config.columns[:m].label = "VOLUME"
    config.columns[:ndt_novo].label = "NDT"
    config.columns[:ndt].label = "NDT"
    config.columns[:obs_trans].label = "OBS"
    config.columns[:pares_novo].label = "PARES"
    config.columns[:pares].label = "PARES"
    config.columns[:peso_novo].label = "PESO"
    config.columns[:peso].label = "PESO"
    config.columns[:updated_at].label = "Ultima Atualização"
    config.columns[:armazenamentos].label = "DEPÓSITOS"
    config.columns[:armazenados_em].label = "DEPÓSITOS"
    config.columns[:depositos].label = "DEPÓSITOS"
    config.columns[:destino].label = "DESTINO"
    config.columns[:status].label = "STATUS"
    config.columns[:tipo].label = "TIPO"
    config.columns[:transportadora].label = "TRANSP"
    config.columns[:user].label = "USR"

    config.columns[:data_inicio].description = "Data Início"
    config.columns[:cxs_novo].description = "Cxs"
    config.columns[:etiqueta].description = "Etiqueta"
    config.columns[:etq].label = "Etiqueta"
    config.columns[:m_novo].description = "Volume"
    config.columns[:ndt_novo].description = "Número de Transporte"
    config.columns[:ndt].description = "Número de Transporte"
    config.columns[:obs_trans].description = "Observação"
    config.columns[:pares_novo].description = "Pares"
    config.columns[:peso_novo].description = "Peso"
    config.columns[:updated_at].description = "Ultima Atualização"
    config.columns[:armazenamentos].description = "Armazenamentos"
    config.columns[:depositos].description = "Depósitos"
    config.columns[:destino].description = "Destino"
    config.columns[:status].description = "Status"
    config.columns[:tipo].description = "Tipo"
    config.columns[:transportadora].description = "Transportadora"
    config.columns[:user].description = "Usuário"


    config.columns[:status].form_ui = :select

    config.list.sorting = [{:status => 'DESC', :data_inicio => 'ASC'}]

    config.list.per_page = Setting.new.qtd_porpagina

    config.search.link.label = "Buscar"
    config.update.link.label = "E"
    config.show.link.label = "M"
    config.update.link.inline = false

    config.actions.exclude :create
    config.actions.exclude :delete

    config.search.columns << :ndt
  end

  def conditions_for_collection
    ['status_id = ?',"#{$LIB}"]
  end

  def edit
    respond_to do |format|
      format.html { redirect_to edit_transporte_path(params[:id]), :layout => false }
    end
  end

  def back
    session[:voltar_para] = request.request_uri
  end

end
